/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ig.ejb.metrica.da.session;

import ig.ejb.metrica.da.session.dto.LineaPlanoDTO;
import ig.util.ejb.IGBean;
import java.util.Date;
import java.util.List;

/**
 *
 * @author usuario
 */
public class PlanoSBean extends IGBean {
    
    public void guardar(List<LineaPlanoDTO> list, int formato) throws Exception{
        try {
            conn = IGBean.getMetricaDA();//getConexion("METRICADA");
            pstmt1 = conn.prepareStatement("INSERT INTO ARCHIVOPLANO ( EMPRESA, FECHA, FORMATO, NUMEROLINEA, LINEA ) VALUES( ?, ?, ?, ?, ? )");
            for ( LineaPlanoDTO lineaPlanoDTO : list ) {
                lineaPlanoDTO.setFormato(formato);
                pstmt1.setString(1, lineaPlanoDTO.getEmpresa());
                pstmt1.setDate(2, new java.sql.Date( lineaPlanoDTO.getFecha().getTime() ) );
                pstmt1.setInt(3, lineaPlanoDTO.getFormato() );
                pstmt1.setInt(4, lineaPlanoDTO.getNumeroDeLinea() );
                pstmt1.setString(5, lineaPlanoDTO.getLinea() );
                pstmt1.executeUpdate();
                pstmt1.clearParameters();
            }
        }finally{
            closeAll();
        }
    }
    
    public void eliminar(String empresa, Date fecha, Integer formato) throws Exception{
        try {
            conn = IGBean.getMetricaDA();//getConexion("METRICADA");
            pstmt1 = conn.prepareStatement("DELETE FROM ARCHIVOPLANO WHERE EMPRESA = ? AND FECHA = ? AND FORMATO = ?");            
            pstmt1.setString(1, empresa);
            pstmt1.setDate(2, new java.sql.Date( fecha.getTime() ) );
            pstmt1.setInt(3, formato );
            pstmt1.executeUpdate();
        } finally {
            closeAll();
        }
    }
    
}
